const connection = require('../app/database');
const Service= require("../service/users");
const {AVATAR_PATH} = require('../const/filePath');
const fs = require("fs");
class UserController {
 //创建用户
 async create(ctx,next){
  const result =await Service.create(ctx.request.body);
  console.log(result);
  ctx.body = result;
  }

  //查询用户
  async getAvatarInfo(ctx,next){
  const userId = ctx.params.userId;
  const avatar =await Service.getAvatarInfo(userId);
  console.log(avatar);
  //保存到用户表
   ctx.response.set('content-type', avatar.mimetype);
   ctx.body = fs.createReadStream(`${AVATAR_PATH}/${avatar.filename}`)
  }



}
module.exports = new UserController();